

#include "stdafx.h"
#include "pf_point.h"

#include "pf_graphicview.h"
#include "pf_painter.h"


/**
 * Default constructor.
 */
PF_Point::PF_Point(PF_Container* parent,
                   const PF_PointAttribute& d)
        :PF_AtomicEntity(parent), data(d) {
    calculateBorders ();
}



void PF_Point::calculateBorders () {
    minV = maxV = data.pos;
}



PF_VectorSolutions PF_Point::getRefPoints() {
	PF_VectorSolutions ret(data.pos);
	return ret;
}



PF_Vector PF_Point::getNearestEndpoint(const PF_Vector& coord, double* dist) {

    if (dist!=NULL) {
        *dist = data.pos.distanceTo(coord);
    }

    return data.pos;
}



PF_Vector PF_Point::getNearestPointOnEntity(const PF_Vector& coord,
        bool /*onEntity*/, double* dist, PF_Entity** entity) {
    if (dist!=NULL) {
        *dist = data.pos.distanceTo(coord);
    }
    if (entity!=NULL) {
        *entity = this;
    }
    return data.pos;
}



PF_Vector PF_Point::getNearestCenter(const PF_Vector& coord, double* dist) {

    if (dist!=NULL) {
        *dist = data.pos.distanceTo(coord);
    }

    return data.pos;
}



PF_Vector PF_Point::getNearestMiddle(const PF_Vector& coord,
                                     double* dist) {
    if (dist!=NULL) {
        *dist = data.pos.distanceTo(coord);
    }

    return data.pos;
}



PF_Vector PF_Point::getNearestDist(double /*distance*/,
                                   const PF_Vector& /*coord*/,
                                   double* dist) {
    if (dist!=NULL) {
        *dist = LX_DOUBLEMAX;
    }
    return PF_Vector(false);
}



double PF_Point::getDistanceToPoint(const PF_Vector& coord,
                                    PF_Entity** entity,
                                    LX_Define::ResolveLevel /*level*/,
									double /*solidDist*/) {
    if (entity!=NULL) {
        *entity = this;
    }
    return data.pos.distanceTo(coord);
}



void PF_Point::moveStartpoint(const PF_Vector& pos) {
	data.pos = pos;
	calculateBorders();
}



void PF_Point::move(PF_Vector offset) {
    data.pos.move(offset);
    calculateBorders();
}



void PF_Point::rotate(PF_Vector center, double angle) {
    data.pos.rotate(center, angle);
    calculateBorders();
}



void PF_Point::scale(PF_Vector center, PF_Vector factor) {
    data.pos.scale(center, factor);
    calculateBorders();
}



void PF_Point::mirror(PF_Vector axisPoint1, PF_Vector axisPoint2) {
    data.pos.mirror(axisPoint1, axisPoint2);
    calculateBorders();
}


void PF_Point::draw(PF_Painter* painter,PF_GraphicView* view, double /*patternOffset*/) {
    if (painter==NULL || view==NULL) {
        return;
    }

    painter->drawPoint(view->toGui(getPos()));
}



/**
 * Dumps the point's data to stdout.
 */
std::ostream& operator << (std::ostream& os, const PF_Point& p) {
    os << " Point: " << p.getData() << "\n";
    return os;
}


// EOF
